var generate = function (numRows) {
  let n = 0,
    ans = [];

  while (n < numRows) {
    if (n === 0) {
      ans.push([1]);
    } else if (n === 1) {
      ans.push([1, 1]);
    } else {
      const ends = ans.at(-1);
      const _ans = [1];
      for (let index = 0; index < ends.length - 1; index++) {
        const start = ends[index],
          end = ends[index + 1];
        _ans.push(start + end);
      }
      _ans.push(1);
      ans.push(_ans);
    }
    n++;
  }
  return ans.at(-1);
};
